Conditions | 1 |
Paths | 32 |
Total Lines | 60 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | $(function(){ |
||
2 | |||
3 | $("body").delegate(".btn-new-worksheet", "click", function(event) |
||
4 | { |
||
5 | event.preventDefault(); |
||
6 | |||
7 | var id_conn = $(this).attr('data-id'); |
||
8 | var conn_name = $(this).attr('data-name'); |
||
9 | |||
10 | var call = eval($(this).attr('data-callback')) || {}; |
||
|
|||
11 | |||
12 | call.success = call.success || new Function(); |
||
13 | call.before = call.before || new Function(); |
||
14 | call.error = call.error || new Function(); |
||
15 | |||
16 | var d = new Date(); |
||
17 | var n = d.getTime(); |
||
18 | |||
19 | var title = $("#worksheet-collector .worksheet-item-title").last().clone(); |
||
20 | |||
21 | if (title.hasClass('active')) |
||
22 | title.removeClass('active'); |
||
23 | |||
24 | var other_tabs = $("div[data-tab][data-conn='" + id_conn + "']"); |
||
25 | |||
26 | var tab_index = (other_tabs.length) ? parseInt(other_tabs.last().attr('data-tab-index')) + 1 : 1; |
||
27 | |||
28 | title.html(conn_name + "~" + tab_index + " <button class='ui small compact basic button btn-remove-worksheet'>x</button>").attr('data-tab', n); |
||
29 | |||
30 | $("#worksheet-collector .worksheet-item-title").last().parent().append(title); |
||
31 | |||
32 | var content = $("#worksheet-collector .worksheet-item-content").last().clone(); |
||
33 | content.empty().attr('data-conn', id_conn); |
||
34 | content.empty().attr('data-tab-index', tab_index); |
||
35 | |||
36 | $("#worksheet-collector .worksheet-item-content").last().parent().append(content); |
||
37 | |||
38 | if (content.hasClass('active')) |
||
39 | content.removeClass('active'); |
||
40 | |||
41 | content.attr('data-tab', n); |
||
42 | content.load(content.attr("data-resource"), { id: n, conn: id_conn }); |
||
43 | |||
44 | $('.menu .item').tab(); |
||
45 | |||
46 | $(title).trigger('click'); |
||
47 | }); |
||
48 | |||
49 | $('.menu .item').tab(); |
||
50 | |||
51 | $("body").delegate(".btn-remove-worksheet", "click", function(event) |
||
52 | { |
||
53 | event.preventDefault(); |
||
54 | event.stopPropagation(); |
||
55 | |||
56 | var tab = $(this).parent().attr('data-tab'); |
||
57 | $("[data-tab='" + tab + "']").remove(); |
||
58 | $("a[data-tab='home']").trigger("click"); |
||
59 | }); |
||
60 | }); |